package com.imut.lagain.repository;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.imut.lagain.entity.Notification;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Optional;

/**
 * 通知数据访问层
 */
@Mapper
public interface NotificationRepository extends BaseMapper<Notification> {
    
    /**
     * 根据ID查找通知
     * @param id 通知ID
     * @return 通知对象
     */
    @Select("SELECT * FROM notification WHERE id = #{id} AND is_deleted = false")
    Optional<Notification> findById(Long id);
    
    /**
     * 批量更新通知
     * @param notifications 通知列表
     * @return 更新记录数
     */
    @Update("<script>"
            + "UPDATE notification "
            + "SET is_read = #{item.isRead}, "
            + "read_at = #{item.readAt}, "
            + "updated_at = #{item.updatedAt} "
            + "WHERE id = #{item.id}"
            + "</script>")
    int updateBatch(List<Notification> notifications);
}